//
//  NSIndexPath+Array.m
//  Byelone
//
//  Created by Qi Liu on 2021/2/26.
//

#import "NSIndexPath+Array.h"

@implementation NSIndexPath (Array)
+ (NSIndexPath *)indexPathWithIndexes:(NSArray *)indexes
{
    return [[NSIndexPath alloc] initWithIndexes:indexes];
}

- (NSIndexPath *)initWithIndexes:(NSArray *)indexes
{
    NSUInteger idx[[indexes count]];
    for (NSInteger i=0; i<[indexes count]; i++) {
        idx[i] = [[indexes objectAtIndex:i] integerValue];
    }
    return [self initWithIndexes:idx length:[indexes count]];
}

- (NSArray *)allIndexes
{
    NSMutableArray *indexes = [NSMutableArray arrayWithCapacity:[self length]];
    for (NSInteger i=0; i<[self length]; i++) {
        [indexes addObject:[NSNumber numberWithInteger:[self indexAtPosition:i]]];
    }
    return [indexes copy];
}

/// 根据section 内的row个数 创建数组
/// @param rows 总row数
/// @param offset 偏移，即从第几个开始，0 即从0开始，offset=1 即从第一个开始
/// @param section section
//+(NSArray * )indexsWithRows:(NSInteger)rows offSet:(NSInteger)offset inSection:(NSInteger)section{
+(NSArray * )indexsWithRows:(NSInteger)rows inSection:(NSInteger)section{
    
    NSMutableArray * indexxArray  = [NSMutableArray array];
    
    for (NSInteger i = 1; i <= rows; i++) {
        
        NSIndexPath * index = [NSIndexPath indexPathForRow:i inSection:section];
        
        [indexxArray addObject:index];
    }
    
    return [indexxArray copy];
}

@end
